/*
Search for a Range

Given a sorted array of integers, find the starting and ending position of a given target value.

Your algorithm's runtime complexity must be in the order of O(log n).

If the target is not found in the array, return [-1, -1].

For example,
Given [5, 7, 7, 8, 8, 10] and target value 8,
return [3, 4].

*/

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
//#include <math>
#include <stack>
#include <queue>
#include <fstream>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include "print.h"
using namespace std;

/**
* Definition for binary tree*/
typedef __int32 uint32_t;


void testForStack()
{
	stack<int> mystack;
	mystack.push(10);
	mystack.push(20);
	mystack.top() -= 5;
	cout << "mystack.top() is now " << mystack.top() << endl;
}

void testForIntToString()
{
	int a = 10;
	stringstream ss;
	ss << a;
	string str = ss.str();
	cout << str << endl;

	string str1 = to_string(a);

}
/*

alpMap[1] = "A";
alpMap[2] = "B";
alpMap[3] = "C";
alpMap[4] = "D";
alpMap[5] = "E";
alpMap[6] = "F";
alpMap[7] = "G";
alpMap[8] = "H";
alpMap[9] = "I";
alpMap[10] = "J";
alpMap[11] = "K";
alpMap[12] = "L";
alpMap[13] = "M";
alpMap[14] = "N";
alpMap[15] = "O";
alpMap[16] = "P";
alpMap[17] = "Q";
alpMap[18] = "R";
alpMap[19] = "S";
alpMap[20] = "T";
alpMap[21] = "U";
alpMap[22] = "V";
alpMap[23] = "W";
alpMap[24] = "X";
alpMap[25] = "Y";
alpMap[26] = "Z";
*/







class Solution2 {
public:
	vector<int> searchRange(int A[], int n, int target) {
		vector<int> result;

		
		auto leftIndex = lower_bound(A, A + n,target);
		auto rightIndex = upper_bound(A, A + n, target);

		if (*leftIndex == target)
		{
			result.push_back(leftIndex - A);
		}
		else
		{
			result.push_back(-1);

		}

		if (*(rightIndex-1) == target)
		{
			result.push_back(rightIndex - A - 1);
		}
		else
		{
			result.push_back(-1);

		}
		return result;
	}
};

class Solution1 {
public:
	int findLeft(int A[],int n, int target)
	{
		
		//cout << A[0] << endl;
		if (n == 0)
		{
			return -1;
		}
		int i = 0;
		int j = n - 1;
		while (i<j)
		{
			int mid =  i +(j-i ) / 2;
			if (A[mid] >= target)
			{
				j = mid;
			}
			else
			{
				i = mid + 1;
			}

			
		}
		if (A[i] == target)
		{
			return i;
		}
		else
		{
			return -1;

		}
		
	}


	int findRight(int A[], int n, int target)
	{
		if (n == 0)
		{
			return -1;
		}

		int i = 0;
		int j = n - 1;

		while (i<=j)
		{
			int mid = i + (j - i) / 2;
			if (A[mid]>target)
			{
				j = mid - 1;
			}
			else{
				i = mid + 1;
			}
		}

		if (A[j] == target)
		{
			return j;
		}
		else
		{
			return -1;
		}

	}
	vector<int> searchRange(int A[], int n, int target) {
		vector<int> result;
		

		int leftIndex, rightIndex;

		leftIndex = findLeft(A, n, target);
		rightIndex = findRight(A, n, target);

		result.push_back(leftIndex);
		result.push_back(rightIndex);

		return result;


	}
};


void func()
{
	auto_ptr<string> ps(new string("jjhou"));

	cout << *ps << endl;
	cout << ps->size() << endl;
}

int main(int argc, char* argv[])
{
	func();



	//string str1;
	int a;
	//ListNode *head = new ListNode(-1);
	//ListNode *p;
	//p = head;

	vector<int> vecInt;

	const int size = atoi(argv[1]);
	int *A;
	A = new int[size];

	int size1 = 0;
	for (int i = 2; i < argc; i++){


		cout << argv[i] << endl;

		a = atoi(argv[i]);

		A[size1++] = a;

		

		//ListNode *item = new ListNode(a);
		//p->next = item;
		//p = p->next;
		//vecInt.push_back(a);

	}

	int dividend = 10, divisor = 1;

	cout <<A[2] << endl;

	//head = head->next;
	Solution s;
	int *B = new int{1};
	vecInt = s.searchRange(B, 1, 1);


	//head = s.swapPairs(head);
	//string str2 = "23";
	//	char a = str2[2];
	//char one = '1';
	//int num = str2[1] - '0';

	//string str3 = str2 + str2[1];
	//cout << num << endl;

	//Solution s;
	//vector<string> vecStr;
	//vecStr = s.generateParenthesis(a);

	//stackTree.push(p->left);
	//stackTree.push(p->right);

	//ListNode *headA = new ListNode(1);
	//ListNode *pa1 = new ListNode(2);
	//ListNode *pa2 = new ListNode(3);
	//headA->next = pa1;
	//pa1->next = pa2;

	//ListNode *headB = new ListNode(4);
	//ListNode *pa1 = new ListNode(2);
	//ListNode *pa2 = new ListNode(3);
	//headA->next = pa1;
	//pa1->next = pa2;







	system("pause");
	return 0;
}